using System;
using System.Collections.Generic;
using System.Text;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel;

namespace DMTT.Workflow.Activities
{
	class MapperActivityValidator : ActivityValidator
	{
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection errors = base.Validate(manager, obj);

            MapperActivity activity = (MapperActivity)obj;

            // only perform check if validating when placed on a workflow
            if (activity.Parent != null)
            {
                if (activity.SourceType == null)
                {
                    errors.Add(ValidationError.GetNotSetValidationError(MapperConstants.SourceType));
                }

                if (activity.DestinationType == null)
                {
                    errors.Add(ValidationError.GetNotSetValidationError(MapperConstants.DestinationType));
                }

                // if the types have been set make sure the mappings have too
                if (activity.DestinationType != null && activity.SourceType != null && activity.Mappings.Count == 0)
                {
                    errors.Add(ValidationError.GetNotSetValidationError(MapperConstants.Mappings));
                }

                // If the types have been set make sure the binding is in place to pick up the source object
                if (activity.SourceType != null && activity.DestinationType != null && !activity.Parameters.Contains(MapperConstants.SourceObject))
                {
                    errors.Add(ValidationError.GetNotSetValidationError(MapperConstants.SourceObject));
                }

                // If the types have been set make sure the binding is in place to pick up the destination object
                if (activity.SourceType != null && activity.DestinationType != null && !activity.Parameters.Contains(MapperConstants.DestinationObject))
                {
                    errors.Add(ValidationError.GetNotSetValidationError(MapperConstants.DestinationObject));
                }
            }

            return errors;
        }
	}
}
